package com.liucxu.zimuzu.Presenter.Impl;

import com.liucxu.zimuzu.Base.ResponseSubscriber;
import com.liucxu.zimuzu.Model.Bean.ArticalBean;
import com.liucxu.zimuzu.Model.IArticalModel;
import com.liucxu.zimuzu.Model.Impl.ArticalModelImpl;
import com.liucxu.zimuzu.Presenter.IArticalPresenter;
import com.liucxu.zimuzu.Utils.TransformUtils;
import com.liucxu.zimuzu.View.IView.IArticalView;

/**
 * 资讯Presenter实现类
 * Created by liukanshan on 2016/12/30.
 */

public class ArticalPresenterImpl implements IArticalPresenter {

    private IArticalView iView;
    private IArticalModel iModel;

    public ArticalPresenterImpl(IArticalView view) {
        iView = view;
        iModel = new ArticalModelImpl();
    }

    @Override
    public void getArticals(int page) {
        iView.showLoading();
        iModel.getArticals(page + "").compose(TransformUtils.<ArticalBean>defaultSchedulers()).subscribe(new ResponseSubscriber<ArticalBean>() {
            @Override
            public void onSuccess(ArticalBean bean) {
                iView.hideLoading();
                iView.setArticals(bean);
            }

            @Override
            public void onFailure(Throwable error) {
                iView.hideLoading();
                iView.showError(error.getMessage());
            }
        });
    }
}
